{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10010259",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams[\"text.usetex\"] = True\n",
    "plt.rcParams[\"font.family\"] = \"serif\"\n",
    "plt.rcParams[\"font.size\"] = \"14\"\n",
    "\n",
    "\n",
    "def plot_results(dfs, show=True, save=True, xlim=5000):\n",
    "    fig, ax1 = plt.subplots()\n",
    "    \n",
    "    from itertools import cycle\n",
    "    lines = [\"-\",\"--\",\"-.\",\":\"]\n",
    "    linecycler = cycle(lines)\n",
    "\n",
    "    \n",
    "    ax1.set_xlabel('Iter [-]')\n",
    "    \n",
    "    psnr_color = 'tab:red'\n",
    "    ax1.set_ylabel('PSNR [dB]', color=psnr_color)\n",
    "    ax1.tick_params(axis='y', labelcolor=psnr_color)\n",
    "    #ax1.set_xlim(0, df['Iter'][df.index[-1]])\n",
    "    ax1.set_xlim(0, xlim)\n",
    "    \n",
    "    ax2 = ax1.twiny()\n",
    "    ax2.set_xlabel('$\\Delta$t [s]')\n",
    "\n",
    "    l1_color = 'tab:blue'\n",
    "    ax3 = ax1.twinx()  # instantiate a second axes that shares the same x-axis\n",
    "    ax3.set_ylabel('L1 [cm]', color=l1_color)\n",
    "    ax3.set_ylim(0, 30)\n",
    "    ax3.tick_params(axis='y', labelcolor=l1_color)\n",
    "    \n",
    "    for name, df in dfs.items():  \n",
    "       \n",
    "        #df = df.iloc[1: , :] # Drop first row which only has 0.0\n",
    "        df = df.set_index('Iter')\n",
    "        \n",
    "        line_style = next(linecycler)\n",
    "\n",
    "        \n",
    "        ax1.plot(df.index, df['PSNR'], color=psnr_color, linestyle=line_style, label=name)    \n",
    "        ax3.plot(df.index, df['L1'], color=l1_color, linestyle=line_style)\n",
    "\n",
    "    ax2.set_xticks(ax1.get_xticks())\n",
    "    ax2.set_xbound(ax1.get_xbound())\n",
    "    xticklabels = [df['Dt'].loc[xtick].round(0).item() for xtick in ax1.get_xticks()]\n",
    "    print(xticklabels)\n",
    "    ax2.set_xticklabels(xticklabels)\n",
    "    \n",
    "    \n",
    "    #ax1.legend(loc='upper center', fontsize='x-large')\n",
    "    leg = ax1.legend(loc='center right')\n",
    "    [lgd.set_color('black') for lgd in leg.legendHandles]\n",
    "\n",
    "    fig.tight_layout()  # otherwise the right y-label is slightly clipped\n",
    "    if show: plt.show()\n",
    "    if save: \n",
    "        #fig.set_size_inches(3, 2)\n",
    "        out = ''\n",
    "        for name in list(dfs.keys())[:-1]:\n",
    "            out += name + '_vs_'\n",
    "        out += list(dfs.keys())[-1]\n",
    "        print(f\"Saving to: {out}\")\n",
    "        fig.savefig(out + '.svg', dpi=100, transparent=False, bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edc45e33",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    #\"ours_l1\":  pd.read_csv('../room_results_ours_l1.csv'),\n",
    "    \"no depth\": pd.read_csv('../room_results_no_depth_3.csv'),\n",
    "    \"raw depth\": pd.read_csv('../room_results_raw_depth.csv'),\n",
    "    #\"raw depth (w annealing)\": pd.read_csv('../room_results_raw_w_annealing.csv'),\n",
    "    \"weighted depth\":  pd.read_csv('../room_results_ours_wo_thresh.csv'),\n",
    "    #\"weighted + annealed\":  pd.read_csv('../room_results_ours_l2_full.csv'),\n",
    "    \"weighted + annealed\":  pd.read_csv('../room_results_ours_w_annealing.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room_results\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac677682",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    #\"ours_no_anneal_thresh\": pd.read_csv('../replica_office0_ours_wo_anneal_w_thresh.csv').iloc[9:,:],\n",
    "    \"no depth\": pd.read_csv('../replica_office0_no_depth_2.csv'),\n",
    "    #\"ours_median_annealed\": pd.read_csv('../replica_office0_ours_median_annealed.csv'),\n",
    "    #\"ours_median_annealed\": pd.read_csv('../replica_office0_ours_w_anneal_w_median.csv'),    \n",
    "    #\"ours_wo_thresh_10\": pd.read_csv('../replica_office0_ours_wo_anneal_wo_thresh_3.csv'),\n",
    "    #\"ours_wo_thresh\": pd.read_csv('../replica_office0_ours_wo_anneal_wo_thresh_2.csv'),\n",
    "    \"raw\": pd.read_csv('../replica_office0_raw_2.csv'),\n",
    "    \"ours_median\": pd.read_csv('../replica_office0_ours_wo_anneal_w_median.csv'),\n",
    "    #\"ours_median_100\": pd.read_csv('../replica_office0_ours_wo_anneal_median_100_lucky.csv')\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room_results\", xlim=20000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d52e51f",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"room0\": pd.read_csv('../room0_nerf_results.csv'),\n",
    "    \"room1\": pd.read_csv('../room1_nerf_results.csv'),\n",
    "    \"room2\": pd.read_csv('../room2_nerf_results.csv'),\n",
    "    \"office0\": pd.read_csv('../office0_nerf_results.csv'),\n",
    "    \"office1\": pd.read_csv('../office1_nerf_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7327f16",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../room_nerf_no_depth_results.csv'),\n",
    "    \n",
    "    #\"weighted+filtered\": pd.read_csv('../room_nerf_ours_w_thresh_results.csv'),\n",
    "    \"raw\": pd.read_csv('../room_nerf_raw_results.csv'),\n",
    "    \"weighted\": pd.read_csv('../room_nerf_ours_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e9db743",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../room0_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../room0_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../room0_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fa4ea26",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../room1_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../room1_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../room1_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5676517b",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../room2_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../room2_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../room2_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42de5872",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../office0_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../office0_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../office0_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a45fc9c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../office1_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../office1_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../office1_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08cb721d",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../office2_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../office2_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../office2_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09db9418",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../office3_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../office3_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../office3_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e40a7acc",
   "metadata": {},
   "outputs": [],
   "source": [
    "dfs = {\n",
    "    \"no depth\": pd.read_csv('../office4_nerf_no_depth_results.csv'),\n",
    "    \"ours\": pd.read_csv('../office4_nerf_ours_results.csv'),\n",
    "    \"raw\": pd.read_csv('../office4_nerf_raw_results.csv'),\n",
    "}\n",
    "plot_results(dfs, show=True, save=\"room0_results\", xlim=25000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02bbbd47",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
